package com.iepacj.thkjava.innerclass;

public class AnonymousConstructor {

	public static Base getBase(int i) {
		Base base = new Base(i) {
			{
				System.out.println("inside instance init");
			}
			
			@Override
			public void f() {
				System.out.println("in anonymous f()");
				/*
				 * 不要求i是final的, 因为i传递给了匿名内部类父类的构造方法
				 * 并没有在内部类中使用. 下面这句代码就要求i是final的
				 */
				//System.out.println("in anonymous f()" + i);
			}
		};
		return base;
	}
	
	public static void main(String[] args) {
		Base base = getBase(3);
		base.f();
	}
	
}

abstract class Base {
	
	public Base(int i) {
		System.out.println("base constructor: " + i);
	}
	
	public abstract void f();
}